package com.xxy.service.impl;

import com.xxy.entity.vo.ChartLineVO;
import com.xxy.entity.vo.ChartVO;
import com.xxy.mapper.*;
import com.xxy.service.DashBoardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class DashBoardServiceImpl implements DashBoardService {
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private ProductMapper productMapper;
    @Autowired
    private OrderMapper orderMapper;
    @Autowired
    private MessageMapper messageMapper;
    @Autowired
    private CategoryMapper categoryMapper;


    @Override
    public List<ChartVO> statistics() {
        List<ChartVO> chartVOList=new ArrayList<>();
        Long userCount = userMapper.selectCount(null);
        ChartVO chartVOUser = ChartVO.builder().name("用户数量").count(userCount).build();
        Long productCount = productMapper.selectCount(null);
        ChartVO chartVOProduct = ChartVO.builder().name("商品数量").count(productCount).build();
        Long orderCount = orderMapper.selectCount(null);
        ChartVO chartVOOrder = ChartVO.builder().name("订单数量").count(orderCount).build();
        Long messageCount = messageMapper.selectCount(null);
        ChartVO chartVOMessage = ChartVO.builder().name("消息通知").count(messageCount).build();
        Long categoryCount = categoryMapper.selectCount(null);
        ChartVO chartVOCategory = ChartVO.builder().name("分类数量").count(categoryCount).build();
        chartVOList.add(chartVOUser);
        chartVOList.add(chartVOProduct);
        chartVOList.add(chartVOOrder);
        chartVOList.add(chartVOMessage);
        chartVOList.add(chartVOCategory);
        return chartVOList;
    }

    @Override
    public List<ChartLineVO> getProductTrend() {
        return productMapper.selectProductCountByDate();
    }
}
